﻿namespace Algorithms_DataStruct_Lib.SymbolTables;

public class Prime
{
    /// <summary>
    /// 求 max 以内的质数
    /// </summary>
    /// <param name="max"></param>
    /// <returns></returns>
    public static IEnumerable<int> Sieve(int max)
    {
        bool[] composite = new bool[max + 1];
        for (int p = 2; p <= max; p++)
        {
            if (composite[p])
                continue;
            yield return p;

            for (int i = p * p; i <= max; i += p)
            {
                composite[i] = true;
            }
        }
    }
}